const File = require('../index')
const file = new File()
const path = require('path')
class Test {
    constructor() {
        this.init()
        this.read()
    }
    async init() {
        const file_path = path.join(__dirname, 'test.log')
        const options = {
            flags: 'a',
            encoding: 'utf8',
            fd: null,
            mode: 0o666,
            autoClose: true
        }
        const stream = await file.create(file_path, options)
        for (let i = 0; i < 10; i++) {
            stream.write(`hello test this is ${i}\n`)
        }           
    }

    async read () {
        const file_path = path.join(__dirname, 'test.log')
        const options = {
            flags: 'r',
            encoding: null,
            fd: null,
            mode: 0o666,
            autoClose: true
        }
        const stream = await file.read(file_path, options)

        let data = ''
        stream.on('data', function(chunk) {
            data += chunk
        })
        stream.on('end', function(){
            console.log(data)
        })
    }
}

module.exports = new Test()